London-class-8-Helena-Rog-JS-Week1#240
Conversation
| console.log("Hello world"); | ||
| console.log("I've just started to learn JavaScript"); | ||
| console.log(500); | ||
|
|
There was a problem hiding this comment.
Very good start. JavaScript can be challenging and with practice we will get better.
| @@ -1,3 +1,7 @@ | |||
| // Start by creating a variable `greeting` | |||
|
|
|||
| var greeting = "Hello World!" | |||
There was a problem hiding this comment.
As per CYF guidelines we should refrain from using var when declaring a variable and instead use let and const.
There was a problem hiding this comment.
I've been guilty of this mistake all throughout my code:)
jstadnik
left a comment
There was a problem hiding this comment.
Great work! Only issue I've noticed is that you should try working on reusing functions.
Basically if I already have a function
function add(a, b) {
return a + b;
}
And I want to create a function that returns string "The sum of 2 and 3 is 5" I would do this by writing
function printSum(a, b) {
let sum = add(a, b);
return `The sum of ${a} and ${b} is ${sum}`;
}
You can see I'm using the "add" function here, rather than write "a+b" again. This may seem silly for such basic examples, but it's the DRY (don't repeat yourself) rule that matters more once your functions do more complicated stuff.
The functions you write, can be used exactly like the built-in JavaScript functions (e.g. Math.round).
| // Start by creating a variable `message` | ||
| var myName = "Helen"; | ||
| var myNameLength = myName.length; | ||
| var message = "Hello, my name is " + myName + "and my name is " + myNameLength + " characters long." |
There was a problem hiding this comment.
This could be a good place to use string interpolation, i.e
| var message = "Hello, my name is " + myName + "and my name is " + myNameLength + " characters long." | |
| var message = `Hello, my name is ${myName} and my name is ${myNameLength} characters long.` |
| function sum (num1, num2) { | ||
| return num1 + num2; | ||
| } | ||
| var sum = sum(13, 124); |
| var mentor3 = "Mimi"; | ||
| var mentor4 = "Rob"; | ||
| var mentor5 = "Yohannes"; | ||
| var mentor1 = "Daniel"; |
There was a problem hiding this comment.
There's some indentation issues in the file -- basically, everything should start from the very left side, unless it's inside function brackets, or a for loop (you'll learn about these later) or something of this sort.
|
|
||
| function helloGreeting(name) { | ||
| return name; | ||
| } |
There was a problem hiding this comment.
This function doesn't do anything as is -- all the work is being done by the other function. As per instructions, you should have:
- One function that returns the name in all caps
- One function that prints "HELLO "
Note, the second function should call your first function to achieve its goal. See how it's used for age in the example in the readme for this exercise.
| } | ||
|
|
||
| var greeting = helloGreeting; | ||
| var shoutyGreeting = upperCaseGreeting; |
There was a problem hiding this comment.
This is just renaming the function -- is this what you intended to do?
I have left suggested CYF solutions commented out
Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in
HOW_TO_MARK.mdin the root of this repositoryYour Details
Homework Details
Notes
What did you find easy?
What did you find hard?
What do you still not understand?
Any other notes?